import Testing
@testable import RoBiliBiliHotVideo
import Foundation
import SwiftyJSON

@Test func example() async throws {
    // Write your test here and use APIs like `#expect(...)` to check expected conditions.
//    await getSearchHot()
//    await getParsing2()
//    let data = searchHotJsonString.data(using: .utf8)!
    let json = try? JSON(parseJSON: searchHotJsonString)
    let data = try json!.rawData()
    print(json)
    let response = await SearchHotStore.requestSearchHotDebug(data: data)
    print(response)
}
func getSearchHot() async -> SearchHotResponse?{
    let respon = await SearchHotStore.requestSearchHot()
//    print(respon)
    if let response = respon{
        if let items = response.data?.list{
            guard let first = response.data?.list.first else{
                print("not have first")
                return nil
            }
            debugPrint(response)
            print(items.count)
            print(first.bvid)
            return response
        }else{
            print("nil")
            return nil
        }
    }else{
        print("nil")
        return nil
    }
}

func getParsing() async {
    let date = Date.now
    let videos = await SearchHotStore.fetchRankingData()
        
        for video in videos{
            if let video = await ParsingStore.parsing(bvid: video.bvid){
                print(video.data[0].title)
                print(video.data[0].videoURL)
            }else{
                print("'nil'")
            }
        }
    
    print(Date.now.timeIntervalSince(date))
}

func getParsing2() async {
    let date = Date.now
    if let videos = await SearchHotStore.requestSearchHot()?.data?.list{
        
        for video in videos{
            if let video = await ParsingStore.parsing(bvid: video.bvid){
                print(video.data[0].title)
                print(video.data[0].videoURL)
            }else{
                print("'nil'")
            }
        }
    }
    print(Date.now.timeIntervalSince(date))
}
